//
//  ViewController.m
//  JKLeafView
//
//  Created by HelloJingQiu on 16/1/29.
//  Copyright © 2016年 HelloJingQiu. All rights reserved.
//

#import "ViewController.h"
#import "JKLeafProgressView.h"

@interface ViewController (){
    NSTimer *timer;
}

@property (strong,nonatomic) JKLeafProgressView *progress;
@property (assign,nonatomic) CGFloat rate;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor orangeColor];
    
    self.progress = [[JKLeafProgressView alloc]initWithFrame:CGRectMake(36, 200, 248, 35)];
    [self.view addSubview:self.progress];
    
    [_progress startLoading];
    
    timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(update) userInfo:nil repeats:YES];
}

-(void)update{
    _rate += 0.01;
    
    NSLog(@"%g",_rate);
    
    [_progress setProgress:_rate];
    if (_rate >= 0.999) {
        _rate = 0;
        [_progress stopLoading];
        [timer invalidate];
        timer = nil;
    }
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    if (!timer) {
        timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(update) userInfo:nil repeats:YES];
        [_progress startLoading];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
